import { Injectable, Inject } from "@angular/core";
import {
  Resolve,
  RouterStateSnapshot,
  ActivatedRouteSnapshot
} from "@angular/router";
import { HttpClient } from "@angular/common/http";
import { ImgStoreData } from "src/storage/.config/store.type";
import { Observable } from "rxjs";
import { urlApi, ServiceModule } from "../../service.module";
import config from "./../../../../storage/.config/store.config";

@Injectable({
  providedIn: ServiceModule
})
export class HomeResolveService implements Resolve<ImgStoreData> {
  constructor(private http: HttpClient, @Inject(urlApi) private url: string) {}

  resolve(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Observable<ImgStoreData> {
    return this.getFileJson();
  }
 
  getFileJson() {
    const path = config.generate.filename;
    return this.http.get(`${this.url}/${path}`) as Observable<ImgStoreData>;
  }
}
